const { execFileSync } = require("child_process");
function getRankData() {
  stdout = execFileSync("getIcon01.exe").toString();
  let points = stdout.split(",");
  points.pop();
  // console.log(points);
  let arr = [];
  //获得空矩阵
  for (let row = 0; row < 8; row++) {
    arr[row] = [];
    for (let col = 0; col < 20; col++) {
      arr[row][col] = 0;
    }
  }
  //获得二值矩阵
  for (let i = 0; i < points.length / 2; i++) {
    arr[points[i * 2 + 1]][points[i * 2]] = 1;
  }

  //标记区域等级
  let rank = 1;
  //获得分区矩阵(左边)
  for (let i = 0; i < 8; i++) {
    //设置分区
    if (arr[i][2] >= 1) {
      //标志列标记
      arr[i][2] = rank;
      //标志列对应区域标记
      while (true) {
        for (let j = 3; j <= 10; j++) {
          if (arr[i][j] >= 1) {
            arr[i][j] = rank;
          }
        }
        if (i === 7 || arr[i + 1][2] >= 1) {
          rank++;
          break;
        }
        i++;
      }
    }
  }
  //右边
  for (let i = 0; i < 8; i++) {
    //设置分区
    if (arr[i][11] >= 1) {
      //标志列标记
      arr[i][11] = rank;
      //标志列对应区域标记
      while (true) {
        for (let j = 12; j <= 20; j++) {
          if (arr[i][j] >= 1) {
            arr[i][j] = rank;
          }
        }
        if (i === 7 || arr[i + 1][11] >= 1) {
          rank++;
          break;
        }
        i++;
      }
    }
  }
  return arr;
}

// module.exports = arrRanked;
//默认暴露
module.exports = getRankData;
